package it.unisa.dao.implementation;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import it.unisa.beans.Account;
import it.unisa.beans.Route;
import it.unisa.dao.RouteDao;

public class RouteHibernateDao extends HibernateDaoSupport implements RouteDao {

	public void insert(Route route) {
		getHibernateTemplate().saveOrUpdate(route);
	}

	public void update(Route route) {
		getHibernateTemplate().saveOrUpdate(route);
	}

	public void delete(int id) {
		Route route=new Route();
		route.setId_route(id);
		getHibernateTemplate().delete(route);
	}

	public List<Route> find(Route route) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Route.class);
		if(route.getId_route()!=0)
			criteria.add(Restrictions.eq("id_route", route.getId_route()));
		if(route.getTime()!=null)
			criteria.add(Restrictions.eq("time", route.getTime()));
		return (List<Route>)getHibernateTemplate().findByCriteria(criteria);

	}

	public List<Route> findAllRoutes() {
		return getHibernateTemplate().find("from Route");

	}

	public int routeCount() {
		return findAllRoutes().size();
	}

	

}
